﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;


namespace JN.Utility
{
    public class TackTimeTracker
    {
        private Dictionary<string, DateTime> _tackList = new Dictionary<string, DateTime>();

        private static readonly object _uniqueObj = new object();
        public TackTimeTracker()
        {
        }

        public void FlowStart(string flowName)
        {
            lock (_uniqueObj)
            {
                if (!_tackList.ContainsKey(flowName))
                {
                    _tackList.Add(flowName, DateTime.Now);
                }
                else
                {
                    _tackList.Remove(flowName);
                    _tackList.Add(flowName, DateTime.Now);
                }
            }
        }
        public string FlowEnd(string flowName)
        {
            lock (_uniqueObj)
            {
                string info = string.Empty;
                if (_tackList.ContainsKey(flowName))
                {
                    info = flowName + " used Time: " + (DateTime.Now - _tackList[flowName]).TotalSeconds.ToString();
                    _tackList.Remove(flowName);
                }
                return info;
            }
        }
    }
}
